//Pietras93OS
//Longjump
//pietras93@gmail.com
//


#include "include/setjmp.h" /* jmp_buf */

void longjmp(jmp_buf buf, int ret_val)
{
        unsigned *esp;
        if(ret_val==0)
        ret_val++;
        buf->eax = ret_val;
        esp = (unsigned *)buf->esp;
        esp--;
        *esp = buf->eflags;
        esp--;
        __asm__ __volatile__("mov %%cs,%0\n"
                             : "=m"(*esp));
        esp--;
        *esp = buf->eip;
        buf->esp = (unsigned)esp;
        __asm__ __volatile__("movl %0,%%esp\n"
                             "popa\n"
                             "movl -20(%%esp),%%esp\n"
                             "iret\n"
                             :
                             : "m"(buf));
}
